package hwaniiiii.dodol;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CountryFlagNameView extends LinearLayout {

	private ImageView flagView;
	private TextView nameView;
	private String mCountryName;

	public CountryFlagNameView(Context context, AttributeSet attrs) {
		super(context, attrs);
		flagView = new ImageView(context);
		nameView = new TextView(context);
		nameView.setPadding(0, 5, 0, 0);
		nameView.setTextColor(0xFF4d3d3d);
		
		setPadding(5, 5, 5, 5);
		setGravity(Gravity.CENTER);
		setOrientation(LinearLayout.VERTICAL);
		
		LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		layoutParams.gravity = Gravity.CENTER;
		
		addView(flagView);
		addView(nameView, layoutParams);
	}
	
	public CountryFlagNameView(Context context, String country) {
		super(context);
		flagView = new ImageView(context);
		nameView = new TextView(context);
		nameView.setPadding(0, 5, 0, 0);
		nameView.setTextColor(0xFF4d3d3d);
		
		setPadding(5, 10, 5, 10);
		setGravity(Gravity.CENTER);
		setOrientation(LinearLayout.VERTICAL);
		this.setLayoutParams(new LayoutParams(80, 90));
		
		LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		layoutParams.gravity = Gravity.CENTER;
		
		addView(flagView);
		addView(nameView, layoutParams);
		setCountry(country);		
	}


	public void setCountry(String name) {   
		mCountryName = name;
		Integer rid = WorldCupApp.mCountryFlag.get(name);
		if(rid != null) {
			flagView.setImageResource(rid);
		} else {
			flagView.setImageResource(R.drawable.no_flag);
		}
		nameView.setText(name);
	
		if(name.length() > 5) {
			nameView.setTextSize(10);	
		} else {
			nameView.setTextSize(13);
		}
	}
	
	public String getCountryName() {
		return mCountryName;
	}
	
	
	
}
